/**
 * Created by IntelliJ IDEA
 *
 * @author zhengjie
 * @Date:2022/1/8 11:36
 * @Version 1.0
 */
package com.zj.ssm.service.impl;

import com.zj.ssm.mapper.BranchMapper;
import com.zj.ssm.pojo.domain.Branch;
import com.zj.ssm.pojo.domain.BranchQUERY;
import com.zj.ssm.pojo.domain.vo.BranchVO;
import com.zj.ssm.result.AjaxResult;
import com.zj.ssm.service.BranchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BranchServiceImpl implements BranchService {

    @Autowired
    public BranchMapper branchMapper;

    @Override
    public AjaxResult list() {
        List<Branch> branches = branchMapper.listAll();
        return AjaxResult.success(branches);
    }

    @Override
    public AjaxResult liststate() {
        List<Branch> branch = branchMapper.liststate();
        return AjaxResult.success(branch);
    }

    @Override
    public AjaxResult getbra(Integer id) {
       BranchVO b = branchMapper.getbra(id);
        return AjaxResult.success(b);
    }

    @Override
    public AjaxResult updatebra(BranchVO branchVO) {
        int i = branchMapper.updatebra(branchVO);
        if (i>0){
            return AjaxResult.success();
        }
        return AjaxResult.fail();
    }

    @Override
    public AjaxResult addbra(BranchVO branchVO) {
        BranchVO branchVO1 = branchMapper.getbraName(branchVO);
        if (branchVO1==null){
            int i = branchMapper.addbra(branchVO);
            if (i>0){
                return AjaxResult.success();
            }
        }
        return AjaxResult.fail();
    }

    @Override
    public AjaxResult querybra() {
       List<BranchQUERY> branchQUERIES = branchMapper.querybra();
        return AjaxResult.success(branchQUERIES);
    }

    @Override
    public AjaxResult updateBranch(Integer id) {
        int i =branchMapper.updateBranch(id);
        if (i>0){
            return AjaxResult.success();
        }
        return AjaxResult.fail();
    }

    @Override
    public AjaxResult branchUpdate(Integer id) {
        int i =branchMapper.branchUpdate(id);
        if (i>0){
            return AjaxResult.success();
        }
        return AjaxResult.fail();
    }




}
